/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef _STDIO_H
#define _STDIO_H

#include <stdarg.h>
#include <stddef.h>
#if defined __cplusplus
using namespace std;
#ifdef EXPORT_LOCAL
#undef EXPORT_LOCAL
#endif
#define EXPORT_LOCAL extern "C"
#else
#define EXPORT_LOCAL extern
#endif

#if defined __cplusplus
namespace std {
#endif

	/**
	 * Writes into the array pointer by str a C string consisting in format with its format tags
	 * expanded to the values of the argument list arg formatted appropiately.
	 * This function behaves exactly as sprintf except that the variable argument list is passed
	 * as a va_list instead of a succession of arguments, which becomes specially useful when the
	 * argument list to be passed comes itself from a variable argument list in the calling function.
	 * vsprintf does not call the va_end macro.
	 *
	 * @param buf Array of char elements where the resulting string is to be stored.
	 * @param fmt C string that contains the text to be written to the buf.
	 * It can optionally contain embedded format tags that are substituted by the values specified in
	 * the arg variable argument list and formatted as requested.
	 * The format tags follow this prototype:
	 * %[flags][width][.precision][length]specifier
	 * Where specifier is the most significant one and defines the type and the interpretation of the
	 * value of the coresponding argument:
	 * <table>
	 *  <tr>
	 *   <td><b>specifier</b></td><td><b>Output</b></td><td><b>Example</b></td>
	 *  </tr>
	 *  <tr>
	 *   <td>c</td><td>Character</td><td>a</td>
	 *  </tr>
	 *  <tr>
	 *   <td>d or i</td><td>Signed decimal integer</td><td>392</td>
	 *  </tr>
	 *  <tr>
	 *   <td>e</td><td>Scientific notation (mantise/exponent) using e character</td><td>3.9265e+2</td>
	 *  </tr>
	 *  <tr>
	 *   <td>E</td><td>Scientific notation (mantise/exponent) using E character</td><td>3.9265E+2</td>
	 *  </tr>
	 *  <tr>
	 *   <td>f</td><td>Decimal floating point</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>g</td><td>Use the shorter of %e or %f</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>G</td><td>Use the shorter of %E or %f</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>o</td><td>Signed octal</td><td>610</td>
	 *  </tr>
	 *  <tr>
	 *   <td>s</td><td>String of characters</td><td>sample</td>
	 *  </tr>
	 *  <tr>
	 *   <td>u</td><td>Unsigned decimal integer</td><td>7235</td>
	 *  </tr>
	 *  <tr>
	 *   <td>x</td><td>Unsigned hexadecimal integer</td><td>7fa</td>
	 *  </tr>
	 *  <tr>
	 *   <td>X</td><td>Unsigned hexadecimal integer (capital letters)</td><td>7FA</td>
	 *  </tr>
	 *  <tr>
	 *   <td>p</td><td>Pointer address</td><td>B800:0000</td>
	 *  </tr>
	 *  <tr>
	 *   <td>n</td><td>Nothing printed. The argument must be a pointer to a signed int, where the number of characters written so far is stored.</td><td></td>
	 *  </tr>
	 *  <tr>
	 *   <td>%</td><td>A % followed by another % character will write a % sign.</td><td></td>
	 *  </tr>
	 * </table>
	 * The tag can also contain flags, width, .precision and modifiers sub-specifiers, which are optional and follow these specifications:
	 * <table>
	 *  <tr>
	 *   <td>-</td>
	 *   <td>Left-justify within the given field width; Right justification is the default (see width sub-specifier).</td>
	 *  </tr>
	 *  <tr>
	 *   <td>+</td>
	 *   <td>Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>(space)</td>
	 *   <td>If no sign is going to be written, a blank space is inserted before the value.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>#</td>
	 *   <td>Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.
	 *			Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written.
	 *			Used with g or G the result is the same as with e or E but trailing zeros are not removed.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>0</td>
	 *   <td>Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).</td>
	 *  </tr>
	 * </table>
	 *
	 * @param args An object representing the variable arguments list. It shall have already been initialized by the va_start macro defined in cstdarg.
	 */
	EXPORT_LOCAL int vsprintf(char *buf, const char *fmt, va_list args);
	/**
	 * Writes into the array pointed by str a C string consisting on a sequence of data formatted as
	 * the format argument specifies. After the format parameter, the function expects at least as many
	 * additional arguments as specified in format.
	 * This function behaves exactly as printf does, but writing its results to a string instead of stdout.
	 * The size of the array passed as str should be enough to contain the entire formatted string.
	 *
	 * @param buf Array of char elements where the resulting string is to be stored.
	 * @param fmt C string that contains the text to be written to the buf.
	 * It can optionally contain embedded format tags that are substituted by the values specified in
	 * the arg variable argument list and formatted as requested.
	 * The format tags follow this prototype:
	 * %[flags][width][.precision][length]specifier
	 * Where specifier is the most significant one and defines the type and the interpretation of the
	 * value of the coresponding argument:
	 * <table>
	 *  <tr>
	 *   <td><b>specifier</b></td><td><b>Output</b></td><td><b>Example</b></td>
	 *  </tr>
	 *  <tr>
	 *   <td>c</td><td>Character</td><td>a</td>
	 *  </tr>
	 *  <tr>
	 *   <td>d or i</td><td>Signed decimal integer</td><td>392</td>
	 *  </tr>
	 *  <tr>
	 *   <td>e</td><td>Scientific notation (mantise/exponent) using e character</td><td>3.9265e+2</td>
	 *  </tr>
	 *  <tr>
	 *   <td>E</td><td>Scientific notation (mantise/exponent) using E character</td><td>3.9265E+2</td>
	 *  </tr>
	 *  <tr>
	 *   <td>f</td><td>Decimal floating point</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>g</td><td>Use the shorter of %e or %f</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>G</td><td>Use the shorter of %E or %f</td><td>392.65</td>
	 *  </tr>
	 *  <tr>
	 *   <td>o</td><td>Signed octal</td><td>610</td>
	 *  </tr>
	 *  <tr>
	 *   <td>s</td><td>String of characters</td><td>sample</td>
	 *  </tr>
	 *  <tr>
	 *   <td>u</td><td>Unsigned decimal integer</td><td>7235</td>
	 *  </tr>
	 *  <tr>
	 *   <td>x</td><td>Unsigned hexadecimal integer</td><td>7fa</td>
	 *  </tr>
	 *  <tr>
	 *   <td>X</td><td>Unsigned hexadecimal integer (capital letters)</td><td>7FA</td>
	 *  </tr>
	 *  <tr>
	 *   <td>p</td><td>Pointer address</td><td>B800:0000</td>
	 *  </tr>
	 *  <tr>
	 *   <td>n</td><td>Nothing printed. The argument must be a pointer to a signed int, where the number of characters written so far is stored.</td><td></td>
	 *  </tr>
	 *  <tr>
	 *   <td>%</td><td>A % followed by another % character will write a % sign.</td><td></td>
	 *  </tr>
	 * </table>
	 * The tag can also contain flags, width, .precision and modifiers sub-specifiers, which are optional and follow these specifications:
	 * <table>
	 *  <tr>
	 *   <td>-</td>
	 *   <td>Left-justify within the given field width; Right justification is the default (see width sub-specifier).</td>
	 *  </tr>
	 *  <tr>
	 *   <td>+</td>
	 *   <td>Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>(space)</td>
	 *   <td>If no sign is going to be written, a blank space is inserted before the value.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>#</td>
	 *   <td>Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.
	 *			Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written.
	 *			Used with g or G the result is the same as with e or E but trailing zeros are not removed.</td>
	 *  </tr>
	 *  <tr>
	 *   <td>0</td>
	 *   <td>Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).</td>
	 *  </tr>
	 * </table>
	 *
	 * @param ... An object representing the variable arguments list. It shall have already been initialized by the va_start macro defined in cstdarg.
	 */
	EXPORT_LOCAL int sprintf(char *buf, const char *fmt, ...);
    EXPORT_LOCAL int printf(const char *format, ...);
	
#if defined __cplusplus
}
#endif

#endif
